﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Web.Http;
using MoskieBlog.Data.Models;
using MoskieBlog.Data;

namespace MoskieBlog.Controllers.Api
{
    public class ChalkMarkController : ApiController
    {
        private MoskieBlogDbContext db = new MoskieBlogDbContext();

        // GET /api/chalkmark
        public IEnumerable<ChalkMark> Get()
        {
            return db.ChalkMarks;
        }

        // GET /api/chalkmark/5
        public ChalkMark Get(int id)
        {
            return db.ChalkMarks.Single(cm => cm.ChalkMarkId == id);
        }

        // POST /api/chalkmark
        public void Post(ChalkMark value)
        {
            db.ChalkMarks.Add(value);
            db.SaveChanges();
        }

        // PUT /api/chalkmark/5
        public void Put(int id, ChalkMark value)
        {
            ChalkMark toUpdate = db.ChalkMarks.Single(cm => cm.ChalkMarkId == id);

            toUpdate.Latitude = value.Latitude;
            toUpdate.Longitude = value.Longitude;
            toUpdate.Description = value.Description;

            db.SaveChanges();
        }

        // DELETE /api/chalkmark/5
        public void Delete(int id)
        {
            db.ChalkMarks.Remove(db.ChalkMarks.Single(cm => cm.ChalkMarkId == id));
            db.SaveChanges();
        }
    }
}
